/***** 
The Passive-Aggressive Voter: The Calculus of Casting an Invalid Vote in European Democracies
Political Research Quarterly (DOI: 10.1177/1065912916662356)
Replication File

Mert Moral
09.08.2016
*****/

/*
Notes:
- Please change the working directory and data file name.
*/

** Table and Figures
use "/Users/mmoral/Dropbox/SUNY Binghamton PhD/Miscellaneous/The Passive-Aggressive Voter_The Calculus of Casting an Invalid Vote in European Democracies/Replication/Replication Data_09.08.16.dta", clear
cd "/Users/mmoral/Dropbox/SUNY Binghamton PhD/Miscellaneous/The Passive-Aggressive Voter_The Calculus of Casting an Invalid Vote in European Democracies/Replication/Graphs"

* Table 1
global controls com age sex educ idst satis 
eststo m1: mlogit invv4 c.polinf2##c.countpfwe i.comp $controls, vce(robust) baseoutcome(3)
eststo m2: mlogit invv4 c.polinf2##c.countpfwe $controls if comp==0, vce(robust) baseoutcome(3) 
eststo m3: mlogit invv4 c.polinf2##c.countpfwe $controls if comp!=0, vce(robust) baseoutcome(3) 
esttab m1 m2 m3 using "table1.tex", tex replace b(%10.3f) se stats(ll chi2 N, labels("Log lik." "$\chi^2$" "N") fmt(%10.3f %10.3f %10.0f)) label starlevels($\dag$ 0.1 $\ddag$ 0.05 * 0.01) varlabels(_cons Constant) addnote("Robust standard errors in parentheses. Two-tailed tests.") nonumbers nobase noomit obslast long mtitle("Model.1" "Model.2" "Model.3")

* Figure 1
gen str3 pipe="|"
gen where=0
.ylab=.object.new
.ylab.Declare array list
.ylab.list[1]="0(.01).04"
.ylab.list[2]="0(.05).25"
.ylab.list[3]="0(.1).3"
.ylab.list[4]=".5(.05).75"

mlogit invv4 c.polinf2##c.countpfwe i.comp $controls, vce(robust) baseoutcome(3)
tabstat polinf2 countpfwe comp $controls, stats(mean min p10 median p90 max)
egen tcountpfwe=tag(countpfwe)

local forlab: value label invv4
forval j=0/3 {
local label: label `forlab' `j'
di "`label'"
margins, at(countpfwe=(1.563(.05)5.313) polinf2=(-1.341953 0.0753253 1.338867) comp=0 com=0 age=47 sex=0 educ=2 idst=.8101827 satis=0) predict(outcome(`j')) vsquish
mat r`j'=r(table)'
mat r`j'=r`j'[1..., 1..4]
svmat r`j', names(coef`j')
mat a`j'=r(at)
svmat a`j', names(at`j')
gen str3 txt`j'=""
replace txt`j'="†" if coef`j'4<=0.1
replace txt`j'="‡" if coef`j'4<=0.05
replace txt`j'="*" if coef`j'4<=0.01
local z=`j'+5
sort at`j'2 at`j'1
replace txt`j'="" if mod(_n,15)>3 | mod(_n,15)==0
gen coef`j'5=coef`j'1-(invttail(e(N)-e(k), .05)*coef`j'2)
gen coef`j'6=coef`j'1+(invttail(e(N)-e(k), .05)*coef`j'2)
gen coef`z'1 = coef`j'1[_n-2]
gen coef`z'2=coef`j'5[_n-2] if coef`j'1<coef`j'1[_n-2] & round(at`j'1)==1
replace coef`z'2=coef`j'5 if coef`j'1>coef`j'1[_n-2] & round(at`j'1)==1
replace coef`z'2=. if round(at`j'1)==1 & coef`j'1<coef`j'1[_n-2] & coef`j'5[_n-2]<coef`j'6 | coef`j'5<0 | coef`j'1>coef`j'1[_n-2] & coef`j'5<coef`j'6[_n-2]
replace coef`z'2=coef`j'1 if coef`z'2!=. & coef`j'1>coef`j'1[_n-2] & round(at`j'1)==1
replace coef`z'2=coef`j'1[_n-2] if coef`z'2!=. & coef`j'1<coef`j'1[_n-2] & round(at`j'1)==1
replace where=.5 if `j'==3
replace where=0 if `j'!=3
twoway (scatter where countpfwe if tcountpfwe, ms(i) mlab(pipe) mlabsize(vsmall) mlabgap(-1) mlabpos(6)) /// 
(rarea coef`z'1 coef`z'2 at`j'2 if coef`z'2!=. & coef`z'2<=coef`j'1, fcolor(gs14) fintensity(40) lcolor(white)) ///
(rarea coef`j'1 coef`z'2 at`j'2 if coef`z'2!=. & coef`z'2<=coef`z'1, fcolor(gs14) fintensity(40) lcolor(white)) ///
(connected coef`j'1 at`j'2 if round(at`j'1)==1, clpattern(shortdash) clwidth(vthin) msymbol(i) mlabel(txt`j') mlabsize(vsmall) mlabgap(-1.0) mlabpos(11)) ///
(connected coef`j'1 at`j'2 if round(at`j'1)==0, clpattern(dot) clwidth(vthin) msymbol(i) mlabel(txt`j') mlabsize(vsmall) mlabgap(-1.0) mlabpos(11)) ///
(connected coef`j'1 at`j'2 if round(at`j'1)==-1, clpattern(solid) clwidth(vthin) msymbol(i) mlabel(txt`j') mlabsize(vsmall) mlabgap(-1.0) mlabpos(11)), ///
xlab(1.5(0.75)5.25, nogrid) ylab(`.ylab.list[`j'+1]', gmax) xtitle("Effective Number of Distinct Party Families") ytitle("Pr(`label')") ///
legend(rows(1) order (4 "High Political Information" 5 "Mean Political Information" 6 "Low Political Information") symxsize(6)) name(mloglcoefsh`j', replace)
}
grc1leg mloglcoefsh0 mloglcoefsh1 mloglcoefsh2 mloglcoefsh3, legendfrom(mloglcoefsh3) scale(.65) note("Multinomial Logistic Regression Estimates. Full Sample (Model 1). † p<0.1, ‡ p<0.05, * p<0.01.") saving(mloglshcoefall.gph,replace)
graph export Figure1.pdf, replace

* Figure 2
drop coef* at* txt* tcountpfwe

mlogit invv4 c.polinf2##c.countpfwe $controls if comp==0, vce(robust) baseoutcome(3)
tabstat polinf2 countpfwe $controls if e(sample), stats(mean min p10 median p90 max)
egen tcountpfwe=tag(countpfwe) if e(sample)

local forlab: value label invv4
forval j=0/3 {
local label: label `forlab' `j'
di "`label'"
margins, at(countpfwe=(1.813(.05)5.313) polinf2=(-1.341953 0.0753253 1.338867) com=0 age=47 sex=0 educ=2 idst=.8101827 satis=0) predict(outcome(`j')) vsquish
mat r`j'=r(table)'
mat r`j'=r`j'[1..., 1..4]
svmat r`j', names(coef`j')
mat a`j'=r(at)
svmat a`j', names(at`j')
gen str3 txt`j'=""
replace txt`j'="†" if coef`j'4<=0.1
replace txt`j'="‡" if coef`j'4<=0.05
replace txt`j'="*" if coef`j'4<=0.01
local z=`j'+5
sort at`j'2 at`j'1
replace txt`j'="" if mod(_n,15)>3 | mod(_n,15)==0
gen coef`j'5=coef`j'1-(invttail(e(N)-e(k), .05)*coef`j'2)
gen coef`j'6=coef`j'1+(invttail(e(N)-e(k), .05)*coef`j'2)
gen coef`z'1 = coef`j'1[_n-2]
gen coef`z'2=coef`j'5[_n-2] if coef`j'1<coef`j'1[_n-2] & round(at`j'1)==1
replace coef`z'2=coef`j'5 if coef`j'1>coef`j'1[_n-2] & round(at`j'1)==1
replace coef`z'2=. if round(at`j'1)==1 & coef`j'1<coef`j'1[_n-2] & coef`j'5[_n-2]<coef`j'6 | coef`j'5<0 | coef`j'1>coef`j'1[_n-2] & coef`j'5<coef`j'6[_n-2]
replace coef`z'2=coef`j'1 if coef`z'2!=. & coef`j'1>coef`j'1[_n-2] & round(at`j'1)==1
replace coef`z'2=coef`j'1[_n-2] if coef`z'2!=. & coef`j'1<coef`j'1[_n-2] & round(at`j'1)==1
replace where=.5 if `j'==3
replace where=0 if `j'!=3
twoway (scatter where countpfwe if tcountpfwe, ms(i) mlab(pipe) mlabsize(vsmall) mlabgap(-1) mlabpos(6)) /// 
(rarea coef`z'1 coef`z'2 at`j'2 if coef`z'2!=. & coef`z'2<=coef`j'1, fcolor(gs14) fintensity(40) lcolor(white)) ///
(rarea coef`j'1 coef`z'2 at`j'2 if coef`z'2!=. & coef`z'2<=coef`z'1, fcolor(gs14) fintensity(40) lcolor(white)) ///
(connected coef`j'1 at`j'2 if round(at`j'1)==1, clpattern(shortdash) clwidth(vthin) msymbol(i) mlabel(txt`j') mlabsize(vsmall) mlabgap(-1.0) mlabpos(11)) ///
(connected coef`j'1 at`j'2 if round(at`j'1)==0, clpattern(dot) clwidth(vthin) msymbol(i) mlabel(txt`j') mlabsize(vsmall) mlabgap(-1.0) mlabpos(11)) ///
(connected coef`j'1 at`j'2 if round(at`j'1)==-1, clpattern(solid) clwidth(vthin) msymbol(i) mlabel(txt`j') mlabsize(vsmall) mlabgap(-1.0) mlabpos(11)), ///
xlab(1.5(0.75)5.25, nogrid) ylab(`.ylab.list[`j'+1]', gmax) xtitle("Effective Number of Distinct Party Families") ytitle("Pr(`label')") legend(off) title("Voluntary Voting") name(mlog0coefsh`j', replace)
}

rename (coef01 at01 at02) (probvol fendpfvol finfvol)
drop coef* at* txt* tcountpfwe

mlogit invv4 c.polinf2##c.countpfwe $controls if comp!=0, vce(robust) baseoutcome(3)
tabstat polinf2 countpfwe $controls if e(sample), stats(mean min p10 median p90 max)
egen tcountpfwe=tag(countpfwe) if e(sample)

local forlab: value label invv4
forval j=0/3 {
local label: label `forlab' `j'
di "`label'"
margins, at(countpfwe=(1.563(.05)3.813) polinf2=(-1.341953 0.0753253 1.338867) com=0 age=47 sex=0 educ=2 idst=.8101827 satis=0) predict(outcome(`j')) vsquish
mat r`j'=r(table)'
mat r`j'=r`j'[1..., 1..4]
svmat r`j', names(coef`j')
mat a`j'=r(at)
svmat a`j', names(at`j')
gen str3 txt`j'=""
replace txt`j'="†" if coef`j'4<=0.1
replace txt`j'="‡" if coef`j'4<=0.05
replace txt`j'="*" if coef`j'4<=0.01
local z=`j'+5
sort at`j'2 at`j'1
replace txt`j'="" if mod(_n,15)>3 | mod(_n,15)==0
gen coef`j'5=coef`j'1-(invttail(e(N)-e(k), .05)*coef`j'2)
gen coef`j'6=coef`j'1+(invttail(e(N)-e(k), .05)*coef`j'2)
gen coef`z'1 = coef`j'1[_n-2]
gen coef`z'2=coef`j'5[_n-2] if coef`j'1<coef`j'1[_n-2] & round(at`j'1)==1
replace coef`z'2=coef`j'5 if coef`j'1>coef`j'1[_n-2] & round(at`j'1)==1
replace coef`z'2=. if round(at`j'1)==1 & coef`j'1<coef`j'1[_n-2] & coef`j'5[_n-2]<coef`j'6 | coef`j'5<0 | coef`j'1>coef`j'1[_n-2] & coef`j'5<coef`j'6[_n-2]
replace coef`z'2=coef`j'1 if coef`z'2!=. & coef`j'1>coef`j'1[_n-2] & round(at`j'1)==1
replace coef`z'2=coef`j'1[_n-2] if coef`z'2!=. & coef`j'1<coef`j'1[_n-2] & round(at`j'1)==1
replace where=.5 if `j'==3
replace where=0 if `j'!=3
twoway (scatter where countpfwe if tcountpfwe, ms(i) mlab(pipe) mlabsize(vsmall) mlabgap(-1) mlabpos(6)) /// 
(rarea coef`z'1 coef`z'2 at`j'2 if coef`z'2!=. & coef`z'2<=coef`j'1, fcolor(gs14) fintensity(40) lcolor(white)) ///
(rarea coef`j'1 coef`z'2 at`j'2 if coef`z'2!=. & coef`z'2<=coef`z'1, fcolor(gs14) fintensity(40) lcolor(white)) ///
(connected coef`j'1 at`j'2 if round(at`j'1)==1, clpattern(shortdash) clwidth(vthin) msymbol(i) mlabel(txt`j') mlabsize(vsmall) mlabgap(-1.0) mlabpos(11)) ///
(connected coef`j'1 at`j'2 if round(at`j'1)==0, clpattern(dot) clwidth(vthin) msymbol(i) mlabel(txt`j') mlabsize(vsmall) mlabgap(-1.0) mlabpos(11)) ///
(connected coef`j'1 at`j'2 if round(at`j'1)==-1, clpattern(solid) clwidth(vthin) msymbol(i) mlabel(txt`j') mlabsize(vsmall) mlabgap(-1.0) mlabpos(11)), ///
xlab(1.5(0.75)3.75, nogrid) ylab(`.ylab.list[`j'+1]', gmax) xtitle("Effective Number of Distinct Party Families") ytitle("Pr(`label')") legend(off) title("Compulsory Voting") name(mlog1coefsh`j', replace)
}
twoway (scatter where countpfwe if tcountpfwe, ms(i) mlab(pipe) mlabsize(vsmall) mlabgap(-1) mlabpos(6)) /// 
(rarea coef81 coef82 at32 if coef82!=. & coef82<=coef31, fcolor(gs14) fintensity(40) lcolor(white)) ///
(rarea coef31 coef82 at32 if coef82!=. & coef82<=coef81, fcolor(gs14) fintensity(40) lcolor(white)) ///
(connected coef31 at32 if round(at31)==1, clpattern(shortdash) clwidth(vthin) msymbol(i) mlabel(txt3) mlabsize(vsmall) mlabgap(-1.0) mlabpos(11)) ///
(connected coef31 at32 if round(at31)==0, clpattern(dot) clwidth(vthin) msymbol(i) mlabel(txt3) mlabsize(vsmall) mlabgap(-1.0) mlabpos(11)) ///
(connected coef31 at32 if round(at31)==-1, clpattern(solid) clwidth(vthin) msymbol(i) mlabel(txt3) mlabsize(vsmall) mlabgap(-1.0) mlabpos(11)), ///
xlab(1.5(0.75)3.75, nogrid) ylab(.5(.05).75, gmax) yline(.8, lcolor(gs15) lwidth(small)) xtitle("Effective Number of Distinct Party Families") ytitle("Pr(Mainstream Vote)") ///
legend(rows(1) order (4 "High Political Information" 5 "Mean Political Information" 6 "Low Political Information") symxsize(6)) title("Compulsory Voting") name(mlog1coefsh3, replace)
grc1leg mlog0coefsh0 mlog1coefsh0 mlog0coefsh1 mlog1coefsh1 mlog0coefsh2 mlog1coefsh2 mlog0coefsh3 mlog1coefsh3, legendfrom(mlog1coefsh3) rows(4) scale(.65) note("Multinomial Logistic Regression Estimates. Subsamples with Voluntary (Model 2) and Compulsory Voting (Model 3). † p<0.1, ‡ p<0.05, * p<0.01.") saving(mlogshcompcoefall.gph,replace)
graph export Figure2.pdf, replace

* T-test
rename (coef01 at01 at02) (probcomp fendpfcomp finfcomp)
drop coef* at* txt* tcountpfwe

foreach var in vol comp{
replace finf`var'=round(finf`var'*1000)
replace finf`var'=. if finf`var'<1813 | finf`var'>3813
gen `var'uninf=.
gen `var'inf=.
gen `var'fendpf=.
levelsof finf`var', local(levels)
tokenize `levels'
forval i=1/41 {
qui sum prob`var' if finf`var'==``i'' & round(fendpf`var')==-1
replace `var'uninf=`r(mean)' in `i'
qui sum prob`var' if finf`var'==``i'' & round(fendpf`var')==1
replace `var'inf=`r(mean)' in `i'
replace `var'fendpf=``i''/1000 in `i'
}
}
ttest voluninf==compuninf
ttest volinf==compinf

** Supplemental Material/Online Appendices 
* Appendix A. Descriptive Statistics
use "/Users/mmoral/Google Drive/SUNY Binghamton PhD/SPRING 2013-2014/PLSC663V Comparative Political Parties and Elections/The Passive-Aggressive Voter_The Calculus of Casting an Invalid Vote in European Democracies/Analyses/cses merged by MM v3.dta", clear
qui mlogit invv4 c.polinf2##c.countpfwe i.comp $controls, vce(robust) baseoutcome(3)
gen sample=e(sample)
eststo desc: estpost sum inv abstain nvote mvote polinf2 countpfwe comvot2 comvot3 comvot4 $controls agsatis countpfun pk govper union urban inc if sample
qui mlogit invv4 c.polinf2##c.countpfwe $controls if comp==0, vce(robust) baseoutcome(3)
eststo desc2: estpost sum inv abstain nvote mvote polinf2 countpfwe $controls if e(sample)
qui mlogit invv4 c.polinf2##c.countpfwe $controls if comp!=0, vce(robust) baseoutcome(3)
eststo desc3: estpost sum inv abstain nvote mvote polinf2 countpfwe $controls if e(sample)

esttab desc using appendixa.tex, replace cells("mean(fmt(2)) sd(fmt(2)) min(fmt(2)) max(fmt(2)) count(fmt(0))") collabels("Mean" "Std.Dev." "Min." "Max." "N") noobs nonumber label title("Descriptive Statistics") longtable
esttab desc2 using appendixa.tex, append cells("mean(fmt(2)) sd(fmt(2)) min(fmt(2)) max(fmt(2)) count(fmt(0))") collabels("Mean" "Std.Dev." "Min." "Max." "N") noobs nonumber label title("Party Systems with Voluntary Voting") longtable
esttab desc3 using appendixa.tex, append cells("mean(fmt(2)) sd(fmt(2)) min(fmt(2)) max(fmt(2)) count(fmt(0))") collabels("Mean" "Std.Dev." "Min." "Max." "N") noobs nonumber label title("Party Systems with Compulsory Voting") longtable

* Appendix C. Observed and Actual Election Results
latabstat inv abstain nvote mvote if sample, by(pan) format(%9.4f)

* Appendix D. Robustness and Sensitivity Checks
global controls com age sex educ idst
eststo mlogsatis: mlogit invv4 c.polinf2##c.countpfwe i.comp $controls agsatis if sample, vce(robust) baseoutcome(3)
eststo mlogpk:    mlogit invv4 c.pk##c.countpfwe i.comp $controls satis if sample, vce(robust) baseoutcome(3)
eststo mlogun:    mlogit invv4 c.polinf2##c.countpfun i.comp $controls satis if sample, vce(robust) baseoutcome(3)
eststo mlogwcon:  mlogit invv4 c.polinf2##c.countpfwe i.comp $controls satis union urban inc govper if sample, vce(robust) baseoutcome(3)
esttab mlogsatis mlogpk mlogun mlogwcon using "robust1.tex", tex replace b(%10.3f) se stats(ll chi2 N, labels("Log lik." "$\chi^2$" "N") fmt(%10.3f %10.3f %10.0f)) label starlevels($\dag$ 0.1 $\ddag$ 0.05 * 0.01) varlabels(_cons Constant) addnote("Robust standard errors in parentheses. Two-tailed tests.") nonumbers nobase noomit obslast long mtitle("Satis w/ Democracy" "Political Knowledge" "\# Distinct P. Families" "Additional Controls")

* Appendix E. Multivariate Probit Regression Estimates
set seed 61116 /* Please note that multivariate probit regression estimates might differ in replication attempts depending on the random-number seed and Stata version used (Stata/MP 13.1 for Mac (64-bit Intel) is used in empirical analyses). */
eststo mvprob: mvprobit (inv = polinf2 countpfwe nichepolinf comvot2 comvot3 comvot4 com age sex educ idst satis) (abstain = polinf2 countpfwe nichepolinf comvot2 comvot3 comvot4 com age sex educ idst satis) (nvote = polinf2 countpfwe nichepolinf comvot2 comvot3 comvot4 com age sex educ idst satis), dif technique(bhhh nr)
esttab mvprob using "robust2.tex", unstack tex replace b(%10.3f) se stats(ll chi2 N, labels("Log lik." "$\chi^2$" "N") fmt(%10.3f %10.3f %10.0f)) label starlevels($\dag$ 0.1 $\ddag$ 0.05 * 0.01) varlabels(_cons Constant) addnote("Two-tailed tests.") nonumbers nobase noomit obslast long mtitle("mvprobit") 
